@isTest
private class QuoteEquipmentControllerTest {
    static testMethod void testMethod1() {


    	        // 客户
        Account acc = TestUtils.createAccount();
        acc.Level__c = '一级医院';
        insert acc;

      
        // 业务机会
        Opportunity opp = TestUtils.createOpportunity();
        opp.AccountId = acc.Id;
        insert opp;
        Id rt = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        // 产品
        Product__c p = TestUtils.createInst();
        p.Purpose__c = '仪器报价用';
        p.bggsjhdj__c = 10.0;
        p.RecordTypeId = rt;

        
        Product__c p2 = TestUtils.createInst();
        p2.Name = 'aaaa';
        p2.Purpose__c = '仪器报价用';
        p2.bggsjhdj__c = 10.0;
        p2.RecordTypeId = rt;
        insert new Product__c[] {p, p2};

        // 意向产品
        IntentProduct__c ip = TestUtils.createIntentProduct();
        ip.Opportunity__c = opp.Id;
        ip.Product__c = p.Id;
        insert ip;

        User u = [Select PriceProvince__c from User where Id =: UserInfo.getUserId()];
        // 价格
        Price__c price = TestUtils.createPrice();
        price.Product__c = p.Id;
        price.Company__c = '四川省迈克实业有限公司';
        price.InstCost__c = 10.0;
        price.Province__c = u.PriceProvince__c;
        Price__c price2 = TestUtils.createPrice();
        price2.Product__c = p2.Id;
        price2.Company__c = '四川省迈克实业有限公司';
        price2.InstCost__c = 10.0;
        price2.Province__c = u.PriceProvince__c;
        insert new Price__c[] {price, price2};
        
            /// 日期处理
        Integer m = Date.today().month(); //当前月份
        Integer y = Date.today().year();  //当前年份 
       ///取上月
         if(m == 1){
        m = 12 ;
            y -= 1;
        }else{
        m -= 1;
            
        }
        
        String  month = String.valueOf(m) + '月';
        String  year= String.valueOf(y) + '年';
        AveragePrice__c av1 = new AveragePrice__c(
        Product__c = p.Id,
            Company__c = '四川省迈克实业有限公司',
            AveragePrice__c = 1.0,
            Year__c = year,
            Month__c = month

            
        );
          AveragePrice__c av2 = new AveragePrice__c(
       		 Product__c = p2.Id,
            Company__c = '四川省迈克实业有限公司',
            AveragePrice__c = 1.0,
            Year__c = year,
            Month__c = month
            
        );
        insert new AveragePrice__c[] {av2,av1};



        QuoteEquipmentController qe = new QuoteEquipmentController();
        qe.init();
        qe.qid = opp.Id; 
        qe.init();

        qe.getDetails();

        Map<String,Object> paj = (Map<String,Object> )JSON.deserializeUntyped(EncodingUtil.urlDecode(qe.paramJson, 'UTF-8')) ;
        System.debug('QuoteEquipmentControllerTest==>'+paj ); 
        qe.saveJson = EncodingUtil.urlEncode(JSON.serialize(paj.get('intent')),'UTF-8' );
        qe.save();

        System.debug(qe.msg);

        System.assertEquals(1, [select Id from Quote where OpportunityId=:opp.Id].size());
        qe.qid = [select Id from Quote where OpportunityId=:opp.Id].Id ; 
        qe.init();
        qe.getDetails();

        Map<String,Object> searchMap = new Map<String,Object> ();
        searchMap.put('name', '全');
        qe.saveJson =  EncodingUtil.urlEncode(JSON.serialize(searchMap),'UTF-8' );


        
    }
}